def get_input(prompt, valid_responses=None):
    while True:
        user_input = input(prompt).strip()
        if user_input:
            if valid_responses and user_input not in valid_responses:
                print("输入无效，请选择有效选项。")
            else:
                return user_input
        print("输入不能为空，请重新输入。")


def get_amount():
    while True:
        try:
            amount = float(input("请输入金额: "))
            if amount < 0:
                print("金额不能为负数，请重新输入。")
            else:
                return amount
        except ValueError:
            print("请输入一个有效的数字。")


def get_currency(valid_currencies=['cny', 'usd']):
    while True:
        currency = get_input("请输入货币类型（人民币: 'cny', 美元: 'usd'): ", valid_responses=valid_currencies).lower()
        if currency in valid_currencies:
            return currency
        print("货币类型无效，请重新输入。")


def convert_currency(amount, currency, exchange_rate=7.0):
    try:
        if currency == 'usd':
            return amount * exchange_rate
        elif currency == 'cny':
            return amount / exchange_rate
        else:
            return None
    except TypeError:
        print("货币类型转换出错，请重新输入。")
        return None


def display_result(amount, converted_amount):
    if converted_amount is not None:
        print(f"原始金额: {amount:.2f} {currency_to_str(converted_amount)}")
        print(f"转换后的金额: {converted_amount:.2f} {currency_from_str(converted_amount)}")
    else:
        print("转换过程中发生错误。")


def currency_to_str(converted_amount):
    return 'USD' if converted_amount == 1 else 'CNY'


def currency_from_str(converted_amount):
    return 'CNY' if converted_amount == 1 else 'USD'


def main():
    exchange_rate = 7.0
    while True:
        amount = get_amount()
        currency = get_currency()
        converted_amount = convert_currency(amount, currency, exchange_rate)
        display_result(amount, converted_amount)

        continue_choice = get_input("是否继续（y/n）: ", valid_responses=['y', 'n']).lower()
        if continue_choice == 'n':
            print("程序结束。")
            break


if __name__ == "__main__":
    main()